<template>
	<view class="settings">

		<view class="function-list">
			<view class="function-item" @click="gotoChangePassword">
				<view class="function-img">
					<image src="/static/updatePassword.png"></image>
				</view>
				<view class="function-text">修改密码</view>
				<uni-icons type="right" size="18" class="arrow-icon to-right"></uni-icons>
			</view>
			<view class="function-item" @click="gotoDeactivatePage">
				<view class="function-img">
					<image src="/static/deleteAccount.png"></image>
				</view>
				<view class="function-text">注销账号</view>
				<uni-icons type="right" size="18" class="arrow-icon to-right"></uni-icons>
			</view>
			<view class="function-item" @click="gotoScanPage">
				<view class="function-img">
					<image src="/static/sacn.png"></image>
				</view>
				<view class="function-text">扫一扫</view>
				<uni-icons type="right" size="18" class="arrow-icon to-right"></uni-icons>
			</view>
		</view>

	</view>
</template>

<script setup>
	
	// H5扫描二维码
	import jzH5ScanCode from '@/uni_modules/jz-h5-scanCode/js/index.js'

	/**
	 * 跳转注销账号页面
	 */
	const gotoDeactivatePage = () => {
		uni.navigateTo({
			url: "/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate"
		})
	}

	/**
	 * 跳转修改密码页面
	 */
	const gotoChangePassword = () => {
		uni.navigateTo({
			url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd'
		})
	}

	/**
	 * 跳转扫码页面
	 */
	const gotoScanPage = () => {

		// #ifdef H5
		scanCodeH5();
		// #endif

		// #ifndef H5
		scanCodeAPP();
		// #endif
	}

	/**
	 * H5扫码
	 */
	const scanCodeH5 = () => {
		jzH5ScanCode.scanCode({
			scanType: ['qrCode'],
			success: (res) => {
				console.log('扫码成功:', res.result);
				// 第二个参数 '_blank' 表示在新窗口打开
				window.open(res.result, '_blank');
			},
			fail: (res) => {
				console.log('扫码失败:', res.errMsg)
				uni.showModal({
					content: res.errMsg
				})
			}
		})
	}

	/**
	 * 非H5扫描
	 */
	const scanCodeAPP = () => {
		uni.scanCode({
			success: function(res) {
				console.log('条码类型：' + res.scanType);
				console.log('条码内容：' + res.result);
				// 跳转页面
				uni.navigateTo({
					url: `/pages/personal-center/scancode?targetUrl=${encodeURIComponent(res.result)}`
				});
			},
			fail: function(res) {
				console.log('扫码失败:', res.errMsg)
				uni.showModal({
					content: res.errMsg
				})
			}
		});
	}
</script>

<style lang="scss" scoped>
	.settings {
		min-height: 100vh;
		background-color: #FAFAFA;
		padding: 0 60rpx;

		.function-list {

			.function-item {
				display: flex;
				padding: 40rpx 0;
				align-items: center;

				.function-img {
					margin-right: 40rpx;

					image {
						display: block;
						width: 36rpx;
						height: 36rpx;
					}
				}

				.function-text {
					font-size: 32rpx;
				}

				.function-badge {
					font-size: 30rpx;
					color: rgba(181, 181, 181, 1);
				}

				::v-deep .arrow-icon {
					color: #B3B3B3;
				}

				.to-right {
					margin-left: auto;
				}
			}
		}

	}
</style>